]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
Bug 562771 – The clock is inaccurate
authorOwen Taylor <otaylor@src.gnome.org>
Mon, 1 Dec 2008 19:59:59 +0000 (19:59 +0000)
committerOwen Taylor <otaylor@src.gnome.org>
Mon, 1 Dec 2008 19:59:59 +0000 (19:59 +0000)
Fix the clock to update exactly on the minute, rather than at a random
time within the minute.

Patch from RainCT (Siegfried Gevatter)

svn path=/trunk/; revision=98

js/ui/panel.js

index 2c37a7dd89666a7f0817d6f37d8b545adaa9af29..cbbed8d4026e48a2630df42c94fbd225969fae08 100644 (file)
@@ -94,8 +94,8 @@ Panel.prototype = {
 
         global.stage.add_actor(this._group);
 
+        // Start the clock
         this._updateClock();
-        this._startClock();
     },
 
     // Struts determine the area along each side of the screen that is reserved
@@ -122,19 +122,20 @@ Panel.prototype = {
         }
     },
 
-    _startClock: function() {
-        let me = this;
-        // TODO: this makes the clock updated every 60 seconds, but not necessarily on the minute, so it is inaccurate
-        Mainloop.timeout_add_seconds(60,
-            function() {
-                me._updateClock();
-                return true;
-            });
-    },
-
     _updateClock: function() {
-        this._clock.set_text(new Date().toLocaleFormat("%H:%M"));
-        return true;
+        let me = this;
+        let display_date = new Date();
+        let msec_remaining = 60000 - (1000 * display_date.getSeconds() +
+                                      display_date.getMilliseconds());
+        if (msec_remaining < 500) {
+            display_date.setMinutes(display_time.getMinutes() + 1);
+            msec_remaining += 60000;
+        }
+        this._clock.set_text(display_date.toLocaleFormat("%H:%M"));
+        Mainloop.timeout_add(msec_remaining, function() {
+            me._updateClock();
+            return false;
+        });
     },
 
     overlayHidden: function() {